import pygame

pygame.display.init()
SCREEN_SIZE = (240,240)
screen = pygame.display.set_mode(SCREEN_SIZE)
CENTER = (SCREEN_SIZE[0] / 2, SCREEN_SIZE[1] / 2)

class Sphere:
    
    def __init__(self, pos = 0+0j, radius = 2):
        self.pos = pos
        self.radius = 2

speed = 1
sun = Sphere(radius = 4)
planet = Sphere(pos = 0+0.5j, radius = 2)

dt = 0.025
month = int(1/dt)

def trajectory(speed=1.2):
    velocity = speed+0j
    step = 0
    oldpos = planet.pos
    #while not(oldpos.real < 0 and planet.pos.real > 0):
    while True:
        screen.fill((0,0,0)) 
        oldpos = planet.pos
        accel = -(planet.pos / (abs(planet.pos) ** 3))
        velocity += accel * dt
        planet.pos += velocity * dt
        step += 1
        pcoords = planet.pos * 100
        print planet.pos
        pygame.draw.circle(screen, pygame.color.Color("yellow"),CENTER, sun.radius)
        pygame.draw.circle(screen, pygame.color.Color("green"),(int(CENTER[0]+pcoords.real), int(CENTER[1]+pcoords.imag)), planet.radius)
        pygame.display.flip()
        
        
if __name__ == "__main__":
    trajectory()
        
        